package cc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2{
	private String name;
	private int age;
	
	public PersonSortable2(String name,int age){

		this.name = name;
		this.age = age;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public int getAge() {
		return age;
	}


	public void setAge(int age) {
		this.age = age;
	}



	@Override
	public String toString() {
		return name +"-"+ age;
	}
}

class NameComparator implements Comparator{

	@Override
	public int compare(Object o1, Object o2) {
		
		PersonSortable2 a= (PersonSortable2) o1;
		PersonSortable2 b= (PersonSortable2) o2;
		
		int x = a.getName().compareTo(b.getName());
		if (x!= 0)
		return x;
		 else 
		return 0;
		
	}
}

class AgeComparator implements Comparator{

	@Override
	public int compare(Object o1, Object o2) {
		
		PersonSortable2 a = (PersonSortable2) o1;
		PersonSortable2 b = (PersonSortable2) o2;
		
		return a.getAge()-b.getAge();
				
	}
	
}

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String name;
		int age;
		PersonSortable2 [] person = new PersonSortable2[n];
		for (int i= 0; i < n ; i++) {
			name = in.next();
			age = in.nextInt();
			person[i] = new PersonSortable2(name,age);
		}		
		Arrays.sort(person,new NameComparator());
		System.out.println("NameComparator:sort");
		for (PersonSortable2 personSortable : person) {
			System.out.println(personSortable);
		}
		
		Arrays.sort(person,new AgeComparator());
		System.out.println("AgeComparator:sort");
		for (PersonSortable2 personSortable : person) {
			System.out.println(personSortable);
		}
		 System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
	     System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	
	}


}
